<template>
	<statusbar-item tooltip="关闭当前文档" v-if="store.isWork" @click="closeCurrentDocumentFn">
		<i class="iconfont icon-yuyinguanbi center"></i>
	</statusbar-item>
</template>

<script setup lang="ts">
import { API } from '@v/utils/API';
import { useRootStore } from '@v/store';
import { ElMessageBox } from 'element-plus';
import statusbarItem from '@v/components/statusbar/statusbarItem/index.vue';

const store = useRootStore();

function closeCurrentDocumentFn() {
	ElMessageBox.confirm('确定关闭当前文档吗？', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	}).then(() => {
		store.addMessage('insert', 'info', `文档已关闭 "${store.filePath}"`);
		store.setFileInfo(undefined);
		store.setFilePaht(undefined);
		store.setIsWork(false);

		API.send('close-current-document');
	});
}
</script>

<style scoped lang="scss"></style>
